package IO;

import java.io.File;   

import java.io.FileOutputStream;   

import java.io.*;   

public class Output {   
	 FileOutputStream out = null;   
     FileOutputStream outSTr = null;   
     BufferedOutputStream Buff=null;   
     FileWriter fw = null;   
	
	// fileName "C:/add.txt"  
	//通过流的形式写文件到本地硬盘
	public void wirteByOutputStream(String fileName,byte[] content){
        try {
        	 out = new FileOutputStream(new File(fileName));   
	         long begin = System.currentTimeMillis();   
	         out.write(content);
	        /* for (int i = 0; i < content.length; i++) {   
	        	  out.write(content[i]);
	             //out.write("测试java 文件操作\r\n".getBytes());   
	         }  */ 
	         out.close();   
	         long end = System.currentTimeMillis();   
	         System.out.println("FileOutputStream执行耗时:" + (end - begin) + " 豪秒"); 
        }catch (Exception e) {
			e.printStackTrace();
		}
	}

	// fileName "C:/001.txt"  
	//通过缓冲流的形式写文件到本地硬盘
	public void wirteByBufferedOutputStream(String fileName,byte[] content){
        try {
        	  outSTr = new FileOutputStream(new File(fileName));   
              Buff=new BufferedOutputStream(outSTr);   
              long begin0 = System.currentTimeMillis();
              Buff.write(content);
            /*  for (int i = 0; i <  content.length; i++) {   
            	  Buff.write(content[i]);
                  //Buff.write("测试java 文件操作\r\n".getBytes());   
              }   */
              Buff.flush();   
              Buff.close();   
              long end0 = System.currentTimeMillis();   
              System.out.println("BufferedOutputStream执行耗时:" + (end0 - begin0) + " 豪秒");   
        }catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	// fileName "C:/001.txt"  
	//通过FileWriter写文件到本地硬盘
	public void wirteByFileWriter(String fileName,String content){
        try {
            fw = new FileWriter(fileName);   
            long begin3 = System.currentTimeMillis();   
        	fw.write(content);
            fw.close();   
            long end3 = System.currentTimeMillis();   
            System.out.println("FileWriter执行耗时:" + (end3 - begin3) + " 豪秒");    
        }catch (Exception e) {
			e.printStackTrace();
		}
	}

	// fileName "C:/001.txt"  
	//通过FileWriter写文件到本地硬盘
	public void wirteByFileWriter(String fileName,String[] content){
        try {
            fw = new FileWriter(fileName);   
            long begin3 = System.currentTimeMillis();  
            for(String str:content){
            	fw.write(str+"\r\n");
            }
            fw.close();   
            long end3 = System.currentTimeMillis();   
            System.out.println("FileWriter执行耗时:" + (end3 - begin3) + " 豪秒");    
        }catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
    public static void main(String[] args) {   
    	
        try {   
        	//new Output().wirteByBufferedOutputStream();

        } catch (Exception e) {   

            e.printStackTrace();   

        }   

    }


}